public class GasStation0106_134 {
    public int canCompleteCircuit(int[] gas, int[] cost) {
        int sumGas = 0;
        int start = 0;
        int resGas = 0;
        for (int i = 0; i < gas.length; i++) {
            sumGas = sumGas + gas[i] - cost[i];
            resGas = resGas +  gas[i] - cost[i];
            if(resGas < 0){
                resGas = 0;
                start = i+1;
            }
        }
        if (sumGas < 0) return -1;
        return start;
    }
}
